package com.pig4cloud.pigx.system.config.mq;

import com.pig4cloud.pigx.system.constant.SystemMqConstant;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 系统模块mq配置
 *
 * @since 2022/11/28 15:28
 */
@Configuration
public class SystemMqConfig {

    /**
     * system.log
     *
     * @return {@link FanoutExchange}
     * @since 2022/8/17 20:39
     */
    @Bean
    public FanoutExchange systemLogExchange() {
        return new FanoutExchange(SystemMqConstant.EXCHANGE_FANOUT_SYSTEM_LOG);
    }

    /**
     * system.log
     *
     * @return {@link Queue}
     * @since 2022/8/17 20:39
     */
    @Bean
    public Queue systemLogQueue() {
        return new Queue(SystemMqConstant.QUEUE_FANOUT_SYSTEM_LOG);
    }

    /**
     * system.log
     *
     * @param systemLogExchange 交换机
     * @param systemLogQueue    队列
     * @return {@link Binding}
     * @since 2022/8/17 20:43
     */
    @Bean
    public Binding bindStrategyTaskContractHandle(FanoutExchange systemLogExchange, Queue systemLogQueue) {
        return BindingBuilder.bind(systemLogQueue)
                .to(systemLogExchange);
    }

}
